package com.topcheer.common.datasource.exception;

import com.topcheer.common.base.vo.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;

/**
 * @author xutao
 * @Package com.topcheer.common.datasource.exception
 * @Description: ${todo}
 * @date 2020/4/3 14:10
 */
@Slf4j
@RestControllerAdvice
public class DataSourceExceptionHandler {
    @ExceptionHandler(NoDataSourceKeyException.class)
    public BaseResponse handleException(HttpServletResponse response, NoDataSourceKeyException ex) {
        response.setStatus(200);
        log.error(ex.getMessage(), ex);
        return new BaseResponse().code(ex.getStatus()).msg(ex.getMessage());
    }

    @ExceptionHandler(NoDataSourceBuilderException.class)
    public BaseResponse handleException(HttpServletResponse response, NoDataSourceBuilderException ex) {
        response.setStatus(200);
        log.error(ex.getMessage(), ex);
        return new BaseResponse().code(ex.getStatus()).msg(ex.getMessage());
    }
}
